// pages/water/band/index.js
var app = getApp()
var common_Js = require("../../../component/common.js"), fetchApi = require("../../../utils/httpPost.js")
import Toast from '../../../component/vant/toast/toast';
const CryptoJS = require("../../../utils/aesUtil.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    card_num:'',
    submitState: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },
  inputHandle(e){
    console.log('inputHandle', e)
    this.data.card_num = e.detail;
  },
  submitOp(){
    if(this.data.card_num == ''){
      Toast('请输入卡号')
      return;
    }
    this.data.submitState = true;
    this.setData({
      submitState : true,
    })
    var that = this;
    fetchApi.httpPost('/device/water/band/card', {
      card_num: that.data.card_num,
    }, function (res) {
      if (res.data.code == 0) {
        console.log("绑定水卡返回数据", res.data.data)
        Toast.success(res.data.msg);
        setTimeout(function(){
          wx.navigateBack({
            delta: -1
          })
        }, 300)
      } else {
        console.log("绑定水卡返回数据 异常", res.data.msg)
        Toast.fail(res.data.msg);
      }
      
      that.data.submitState = true;
      that.setData({
        submitState : true,
      })
    }, function () {
      that.setData({ isLoading: false, loading: true, netWork: true, })
    })

  }
})